package com.wallet.controller;

import com.wallet.model.dto.UserDto;
import com.wallet.model.po.Order;
import com.wallet.model.po.Record;
import com.wallet.model.po.User;
import com.wallet.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author
 * @version 1.0
 * @description 用户api
 * @date 2023/2/27 0027 16:15
 */
@RestController
public class UserController {
    @Autowired
    UserService userService;


    /**
     * 查询用户钱包余额
     * @param id 用户id
     * @return User对象
     */
    @GetMapping("/select/{id}")
    public User getUser(@PathVariable("id") Long id){
        return userService.getUser(id);
    }

    /**
     * 用户消费接口
     * @param userDto   封装了基本的User对象以及消费金额
     * @return  User对象
     * @throws Exception
     */
    @PostMapping("/consume")
    public User consume(@RequestBody UserDto userDto) throws Exception {
        return userService.consume(userDto);
    }

    /**
     *用户退单接口
     * @param id 订单id
     * @return  User对象
     * @throws Exception
     */
    @PostMapping("/chargeback/{id}")
    public User chargeback(@PathVariable("id") Long id) throws Exception {
        return userService.chargeback(id);
    }


    /**
     * 用户查询金额变动明细
     * @param id 用户id
     * @return  操作记录集合
     */
    @GetMapping("/select/list/{id}")
    public List<Record> getList(@PathVariable("id")Long id){
        return userService.getList(id);
    }
}
